package com.quick.controller;

import com.quick.base.KeyValue;
import com.quick.base.Page;
import com.quick.base.Search;
import com.quick.service.ISysRoleService;
import com.quick.sys.domain.dto.SysRoleDTO;
import com.quick.sys.domain.search.SysRoleSearch;
import com.quick.sys.domain.vo.SysRoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/sys/role")
@Api(tags ="角色管理")
@AllArgsConstructor
public class SysRoleController {
    private final ISysRoleService sysRoleService;
    
    @ApiOperation(value = "角色分页查询列表", notes = "角色分页查询列表")
    @PostMapping("search")
    public Page<SysRoleVo> search(@RequestBody Search<SysRoleSearch> search){
        return sysRoleService.search(search);
    }
    
    @ApiOperation(value = "新增角色", notes = "新增角色")
    @PostMapping("add")
    public Boolean addRole(@RequestBody SysRoleDTO role){
        return sysRoleService.saveSysRole(role);
    }
    
    @ApiOperation(value = "查询角色", notes = "查询角色")
    @GetMapping("query/{id}")
    public SysRoleVo query(@PathVariable("id") Long id){
        return sysRoleService.queryById(id);
    }
    
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @GetMapping("del/{id}")
    public Boolean del(@PathVariable("id") Long id){
        return sysRoleService.delById(id);
    }
    
    @ApiOperation(value = "批量删除角色", notes = "批量删除角色")
    @PostMapping("batchDel")
    public Boolean batchDel(@PathVariable("id") List<Long> ids){
        return sysRoleService.batchDel(ids);
    }
    
    @ApiOperation(value = "全部角色", notes = "全部角色")
    @PostMapping("loadAll")
    public List<KeyValue> loadAll(){
        return sysRoleService.loadAll();
    }
}
